/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.dataInterface;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.utils.UploadUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.acq.entity.breedinfo.AcqBreedInfo;
import com.thinkgem.jeesite.modules.acq.entity.fammer.AcqFarmer;
import com.thinkgem.jeesite.modules.acq.entity.plantinfo.AcqPlantInfo;
import com.thinkgem.jeesite.modules.acq.service.breedinfo.AcqBreedInfoService;
import com.thinkgem.jeesite.modules.acq.service.breedtype.AcqBreedTypeService;
import com.thinkgem.jeesite.modules.acq.service.plantinfo.AcqPlantInfoService;
import com.thinkgem.jeesite.modules.acq.service.planttype.AcqPlantTypeService;

import groovy.transform.Synchronized;

/**
 * 首页
 * 
 * @author lj
 * @version 2018-3-30
 */
@Controller
@RequestMapping(value = "")
public class InfoController extends BaseController {
	@Autowired AcqBreedInfoService breedInfoService;
	@Autowired AcqPlantInfoService plantInfoService;
	
	// 保存种植品信息
	@RequestMapping(value = "savePlant")
	@ResponseBody
	public Map<String,Object> savePlant(AcqPlantInfo info,HttpServletRequest request, HttpServletResponse response) {
		String	relativePath = Global.getConfig("plantphotos");
		String remote = info.getPhoto().replaceAll("_downloads", "/proDataAcq/"+relativePath+"/"+new SimpleDateFormat("yyyyMMdd").format(new Date())) ;
		info.setPhoto(remote);
		return 	plantInfoService.saveInfo(info);
	}
	
	// 保存养殖品信息
	@RequestMapping(value = "saveBreed")
	@ResponseBody
	public Map<String,Object> saveBreed(AcqBreedInfo info,HttpServletRequest request, HttpServletResponse response) {
		String	relativePath = Global.getConfig("breedphotos");
		String remote = info.getPhoto().replaceAll("_downloads", "/proDataAcq/"+relativePath+"/"+new SimpleDateFormat("yyyyMMdd").format(new Date())) ;
		info.setPhoto(remote);
		return 	breedInfoService.saveInfo(info);
	}
	
	/*
	 * 保存照片信息
	 */
	@RequestMapping(value = "/uploadPlant", method = RequestMethod.POST)
	@Synchronized
	@ResponseBody
	public String uploadPlant(HttpServletRequest request) {
		UploadUtils upload = new UploadUtils();
		upload.uploadFile(request, Global.getConfig("plantphotos"));
		return "1";
	}
	
	/*
	 * 保存照片信息
	 */
	@RequestMapping(value = "/uploadBreed", method = RequestMethod.POST)
	@Synchronized
	@ResponseBody
	public String uploadBreed(HttpServletRequest request) {
		UploadUtils upload = new UploadUtils();
		upload.uploadFile(request, Global.getConfig("breedphotos"));
		return "1";
	}
	
}
